import React, { Component } from 'react';
import Adaptive from '../component/adaptive/Adaptive';
import asyncComponent from '../../Bundle';//动态加载组件，用作代码分割
import Navigation from '../component/navigation/Navigation';
import solutionSource from './slide-source/solution';
import webOrationSource from './slide-source/webOration';
import 'swiper/dist/css/swiper.min.css';
import UserAgent from 'pofod/UserAgent';
import { Redirect } from 'react-router-dom';
import {asyncSize} from 'pofod/window.size';
//pc组件
const Banner = asyncComponent(() => import('./banner/Banner'));
const Introduction = asyncComponent(() => import('./Introduction/Introduction'));
const Operation = asyncComponent(() => import('./Business/Operation'));
const Source = asyncComponent(() => import('./Source/Source'));
const Slide = asyncComponent(() => import('../component/slide/Slide'));
const Chose = asyncComponent(() => import('./Chose/Chose'));
const Contact = asyncComponent(() => import('./contact/Contact'));
const Footer = asyncComponent(() => import('../component/footer/Footer'));
//mobile组件
const MobileSource = asyncComponent(() => import('./Source/mobile/MobileSource'));
// const SolutionMobile = asyncComponent(() => import('./solution-mob/SolutionMobile'));由于解决方案内容过多，不适合移动端展示，目前考虑移除
const NewsMobile = asyncComponent(() => import('./news-mob/NewsMobile'));
const FooterMobile = asyncComponent(() => import('../component/footer-mobile/FooterMobile'));
require('./home.less');
class Huimei extends Component {
    state={
        orationSource:[],
        exeJudgment:false
    }
    componentWillMount(){
        webOrationSource(function (data) {
            if(!UserAgent.mobile) {
                this.setState({
                    orationSource: data
                }, () => {
                    this.setState({
                        exeJudgment: true
                    })
                });
            }
        }.bind(this),5);
    };
    componentDidMount(){
      window.addEventListener('resize',()=>{
          if((asyncSize().pageWidth)<1024){
              window.location.href = '/best';
          }
          return null;
      });
    };
    componentWillUnmount(){
        window.removeEventListener('resize',()=>{
            if((asyncSize().pageWidth)<1024){
                window.location.href = '/best';
            }
            return null;
        });
    };
    render() {
        let state = this.state;
        if(UserAgent.mobile) {
            return (
                <Redirect to="/best"/>
            )
        };
        return (
            <div className="App">
                <Navigation refName="company" childNodes="company-a"/>
                <Banner/>
                <Introduction/>
                <Adaptive desktop={<Operation/>} phone={true} size={1200}/>
                <Adaptive desktop={<Source/>} phone={<MobileSource/>} size={1200}/>
                <Adaptive desktop={<Slide idName="swiper-container" slideSource={solutionSource} topic="解决方案" addHost={false} slidesPerView={3} autoplay={1800} spaceBetween={20} speed={800}/>} phone={false} size={1200}/>
                <Chose/>
                <Adaptive desktop={<Slide idName="swiper-contain" slideSource={state.orationSource} topic="最新资讯" speed={700} autoplay={1500} addHost={true} slidesPerView={4} spaceBetween={60}/>} phone={<NewsMobile newsSource={state.orationSource}/>} size={1200} exeJudgment={state.exeJudgment}/>
                <Adaptive desktop={<Contact/>} phone={false} size={1200}/>
                <Adaptive desktop={<Footer codeDis="none"/>} phone={<FooterMobile/>} size={1200}/>
            </div>
        );
    }
}
export default Huimei;